//
//  TLShortStoryCommentTableViewCell.m
//  WXReader
//
//  Created by huaya on 2025/3/26.
//  Copyright © 2025 Andrew. All rights reserved.
//

#import "TLShortStoryCommentTableViewCell.h"

@interface TLShortStoryCommentTableViewCell()

@property (weak, nonatomic) IBOutlet UIView *commentView;
@property (weak, nonatomic) IBOutlet UIView *collectView;
@property (weak, nonatomic) IBOutlet UIView *commentContentView;
@property (weak, nonatomic) IBOutlet UILabel *commentLab;
@property (weak, nonatomic) IBOutlet UIButton *commentBtn;
@property (weak, nonatomic) IBOutlet UIImageView *collectImgView;
@property (weak, nonatomic) IBOutlet UIImageView *sanjiaoImgView;
@property (weak, nonatomic) IBOutlet UIImageView *plImgView;
@property (weak, nonatomic) IBOutlet UILabel *commentTitleLab;
@property (weak, nonatomic) IBOutlet UILabel *collectTitleLab;

@end

@implementation TLShortStoryCommentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.commentView.layer.cornerRadius = 35/2;
    self.collectView.layer.cornerRadius = 35/2;
    
    self.commentView.userInteractionEnabled = YES;
    self.collectView.userInteractionEnabled = YES;
    
    self.commentContentView.layer.cornerRadius = 8;
    
    self.collectView.tag = 200;
    self.commentView.tag = 100;
    
    UITapGestureRecognizer *tagGest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGest:)];
    
    UITapGestureRecognizer *tagGest2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGest:)];
    
    [self.commentView addGestureRecognizer:tagGest];
    [self.collectView addGestureRecognizer:tagGest2];
    
}
- (void)tapGest:(UITapGestureRecognizer *)tapGest{
    UIView *view = tapGest.view;
    
    switch (view.tag) {
        case 100:
        {
            if (self.commentBlock) {
                self.commentBlock();
            }
        }
            break;
        case 200:
        {
            if (self.collectBlock) {
                self.collectBlock();
            }
        }
            break;
            
        default:
            break;
    }
    
}
- (void)setDataModel:(TLBookListForSSModel *)dataModel{
    if (dataModel) {
        _dataModel = dataModel;
        
        NSString *str = [NSString stringWithFormat:@"%@:%@",dataModel.shortCommentVO.name, dataModel.shortCommentVO.content];
        
        NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSFontAttributeName : SYSTEM_FONT(12), NSForegroundColorAttributeName : kBlackColor}];
        
        attributedStr.lineBreakMode = NSLineBreakByTruncatingTail;
        
        [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#333333"] range:NSMakeRange(0, dataModel.shortCommentVO.name.length)];
        
        [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#666666"] range:NSMakeRange(dataModel.shortCommentVO.name.length, dataModel.shortCommentVO.content.length)];
        
        self.commentLab.attributedText = attributedStr;
        
        [self.commentBtn setTitle:[NSString stringWithFormat:@"View all(%@)",dataModel.shortCommentVO.count] forState:UIControlStateNormal];
        
        if (dataModel.collectStatus){
            [self.collectImgView setImage:[UIImage imageNamed:@"hy_ysc"]];
        }else{
            [self.collectImgView setImage:[UIImage imageNamed:@"dgsl_sc"]];
        }
        
        if ([dataModel.shortCommentVO.content isEqualToString:@""]) {
            
            _sanjiaoImgView.hidden = _commentContentView.hidden = YES;
            
        }else{
            
            _sanjiaoImgView.hidden = _commentContentView.hidden = NO;
        }
        
    }
    [self refreshUI];
}
- (IBAction)viewAllAction:(id)sender {
    if (self.viewAllBlock) {
        self.viewAllBlock();
    }
}
- (void)refreshUI{
    
    
    [self.contentView setBackgroundColor:[[MKReaderCfg shared] bgColor]];
    
    if ([MKReaderCfg shared].bgColorIndex.intValue == 0) {
        
        [self.commentView setBackgroundColor:[UIColor whiteColor]];
        
        [self.collectView setBackgroundColor:[UIColor whiteColor]];
        
        [self.plImgView setImage:[UIImage imageNamed:@"dgsl_pl"]];
        
        self.commentTitleLab.textColor = [UIColor hex_666666];
        self.collectTitleLab.textColor = [UIColor hex_666666];
        [self.commentContentView setBackgroundColor:[UIColor whiteColor]];
        self.commentLab.textColor = [UIColor hex_666666];
        [self.commentBtn setTitleColor:[UIColor hex_999999] forState:UIControlStateNormal];
        
        [self.sanjiaoImgView setImage:[UIImage imageNamed:@"Mask group"]];
    }else{
        
        
        [self.commentView setBackgroundColor:[UIColor hex_313538]];
        
        [self.collectView setBackgroundColor:[UIColor hex_313538]];
        
        self.commentTitleLab.textColor = [UIColor whiteColor];
        self.collectTitleLab.textColor = [UIColor whiteColor];
        self.commentLab.textColor = [UIColor whiteColor];
        [self.plImgView setImage:[UIImage imageNamed:@"dgs_pl"]];
        
        [self.commentContentView setBackgroundColor:[UIColor hex_313538]];
        self.commentLab.textColor = [UIColor whiteColor];
        [self.commentBtn setTitleColor:[UIColor hex_999999] forState:UIControlStateNormal];
        
        [self.sanjiaoImgView setImage:[UIImage imageNamed:@"yd_sjx"]];
    }
    
    
}
@end
